home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / aga / bootscreenaga.lha / BootScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-25  |  4.5 KB  |  198 lines

  1. /* Display an IFF picture as the boot screen */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/intuitionbase.h>
  7. #include <intuition/screens.h>
  8. #include <dos/dostags.h>
  9. #include <dos/RDArgs.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18.  
  19. #include "SC:Extras/IFFLib/iff.h"
  20.  
  21. /* Globals */
  22. struct IntuitionBase *IntuitionBase = NULL;
  23. struct GfxBase *GfxBase = NULL;
  24. struct Library *IFFBase = NULL;
  25. IFFL_HANDLE iff = NULL;
  26. struct {
  27.    ULONG blksize;
  28.    ULONG *ctable;
  29. } RememberColors;
  30. BOOL OptsForceNTSC;
  31.  
  32.  
  33. UBYTE *qqq_VersionString = "$VER: BootScreen 1.00 by Joseph Luk (24.12.93)";
  34.  
  35.  
  36. /* Protos */
  37. VOID OpenAll (VOID);
  38. VOID CloseAll (int);
  39. VOID SetupScrColors (VOID);
  40. ULONG ExtendFrac (UBYTE);
  41.  
  42.  
  43. VOID main (VOID)
  44. {
  45.    struct NewScreen newscr;
  46.    struct Screen *scr;
  47.    struct IFFL_BMHD *bmhd;
  48.    
  49.    SetTaskPri(FindTask(NULL),2);
  50.  
  51.    OpenAll();
  52.    
  53.    bmhd = IFFL_GetBMHD(iff);
  54.    if (bmhd == NULL)
  55.    {
  56.       puts ("Not an IFF ILBM file.");
  57.       CloseAll(10);
  58.    }
  59.  
  60.    /* Set up screen parameters */
  61.    memset(&newscr,0,sizeof(struct NewScreen));
  62.    newscr.Type = CUSTOMSCREEN | SCREENQUIET;
  63.    newscr.Width = bmhd->w;
  64.    newscr.Height = bmhd->h;
  65.    newscr.Depth = bmhd->nPlanes;
  66.    newscr.ViewModes = IFFL_GetViewModes(iff);
  67.    
  68.    SetupScrColors();
  69.    
  70.    scr = OpenScreenTags (&newscr,
  71.                          SA_DisplayID, (OptsForceNTSC ? NTSC_MONITOR_ID : 0)| newscr.ViewModes,
  72.                          SA_Colors32, RememberColors.ctable,
  73.                          TAG_DONE);
  74.    if (scr == NULL) {
  75.       puts ("Can't open screen!");
  76.       CloseAll(10); }
  77.  
  78.    
  79.    /* And display the picture!! */
  80.    if ( !IFFL_DecodePic (iff, &scr->BitMap) )
  81.    {
  82.       puts ("Error displaying picture.");
  83.       CloseAll(5);
  84.    }
  85.    
  86.  
  87.    /* Go into a loop waiting for our screen to be shoved to the back */
  88.    SetTaskPri(FindTask(NULL),-1);
  89.    while (IntuitionBase->FirstScreen == scr) { Delay(50); }
  90.    
  91.    CloseScreen (scr);
  92.    
  93.    CloseAll(0);
  94. }
  95.  
  96.  
  97. VOID OpenAll (VOID)
  98. {
  99.    UBYTE *ArgTemplate = "IFFPICTURE/A,FORCENTSC/S";
  100.    struct RDArgs *ArgsStruct;
  101.    LONG Args[2];
  102.  
  103.    IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library",39L);
  104.    if (IntuitionBase == NULL)
  105.    {
  106.       puts ("You must have OS Version 39 or better (Release 3.0) to use this program.");
  107.       CloseAll(20);
  108.    }
  109.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39L);
  110.    
  111.    IFFBase = OpenLibrary (IFFNAME,IFFVERSION);
  112.    if (IFFBase == NULL)
  113.    {
  114.       printf ("You must have Christian A. Weber's iff.library version %ld or better to use\nthis program.\n",IFFVERSION);
  115.       CloseAll(20);
  116.    }
  117.    
  118.    /* Get arguments, open file */
  119.    Args[0] = NULL;
  120.    Args[1] = FALSE;
  121.    ArgsStruct = ReadArgs(ArgTemplate,&Args[0],NULL);
  122.    if (Args[0] == NULL)
  123.    {
  124.       puts ("Required argument missing.");
  125.       FreeArgs(ArgsStruct);
  126.       CloseAll(20);
  127.    }
  128.    
  129.    iff = IFFL_OpenIFF ((UBYTE *)Args[0], IFFL_MODE_READ);
  130.    if (iff == NULL)
  131.    {
  132.       puts ("Can't open IFF file.");
  133.       FreeArgs(ArgsStruct);
  134.       CloseAll(10);
  135.    }
  136.    
  137.    OptsForceNTSC = Args[1];
  138.    
  139.    FreeArgs(ArgsStruct);
  140.    
  141.    
  142.    /* Misc stuff */
  143.    RememberColors.ctable = NULL;
  144.    
  145. }
  146.  
  147. VOID CloseAll (rc)
  148. int rc;
  149. {
  150.    if (RememberColors.ctable) FreeMem(RememberColors.ctable,RememberColors.blksize);
  151.    
  152.    if (iff) IFFL_CloseIFF(iff);
  153.  
  154.    if (IFFBase) CloseLibrary (IFFBase);
  155.    if (GfxBase) CloseLibrary ((struct Library *)GfxBase);
  156.    if (IntuitionBase) CloseLibrary ((struct Library *)IntuitionBase);
  157.    
  158.    exit(rc);
  159. }
  160.  
  161. VOID SetupScrColors (VOID)
  162. {
  163.    APTR CMAPPtr;
  164.    ULONG numregs;
  165.    UWORD c;
  166.    
  167.    CMAPPtr = IFFL_FindChunk(iff, ID_CMAP);
  168.    if (CMAPPtr == NULL) return;   
  169.  
  170.    numregs = *( ((ULONG *)CMAPPtr) + 1 );
  171.       /* Number of color registers defined in CMAP chunk, (numcolors * 3) */
  172.    
  173.    /* Block size = (array of ULONGs) number of registers + first control entry + terminating entry */
  174.    RememberColors.blksize = sizeof(ULONG) * (numregs + 2);
  175.    RememberColors.ctable = AllocMem(RememberColors.blksize,MEMF_CLEAR);
  176.  
  177.    (RememberColors.ctable)[0] = (numregs/3)<<16;
  178.  
  179.    /* Fill in the color values! */   
  180.    for (c=1; c<=numregs; c++)
  181.       (RememberColors.ctable)[c] = ExtendFrac ( *( ((UBYTE *)CMAPPtr)+7+c ) );
  182.       
  183. }
  184.  
  185. ULONG ExtendFrac (input)
  186. UBYTE input;
  187. {
  188.    ULONG retval;
  189.    UBYTE *trickptr = (UBYTE *)&retval;
  190.    
  191.    trickptr[0] = input;
  192.    trickptr[1] = input;
  193.    trickptr[2] = input;
  194.    trickptr[3] = input;
  195.    
  196.    return (retval);
  197. }
  198.